package com.dylan.springdatajpa.persistence.entity.common;

import com.dylan.springdatajpa.config.SnowFlowId;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.Column;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * @author zhangshaojian
 * @description 实体基类
 * @date 2022/2/11 15:55
 */
@Getter
@Setter
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public class BaseEntity implements Serializable {

    private static final long serialVersionUID = -7237968912063695152L;

    @Id
    @GenericGenerator(name = "snowFlowId", strategy = SnowFlowId.GENERATOR)
    @GeneratedValue(generator = "snowFlowId")
    protected Long id;

    @CreatedDate
    @Column(updatable = false)
    protected LocalDateTime createAt;

    @LastModifiedDate
    protected LocalDateTime lastModifyAt;
}
